<?
$rightCol  = 1;
$eventMenu = 0;
include('includes/appInit.php');
include('includes/header.php');
$resource = new ResourceProviders();
if ($_GET['search'] == 1) {
	$ageYear  = $_POST['ageYear'];
	$ageMonth = $_POST['ageMonth'];
	$zip      = $_POST['zip'];
	
	/*
	 * Check for valid search term
	 */
	if ( empty($_POST['zip']) || (empty($ageYear) && empty($ageMonth)) ) {
		$error = 1;
		$errorDivDisplay = '';
		$errorMessage = 'You must enter a zip code and child age.';
	} else {
		$error = 0;
		$errorDivDisplay = 'none';
		/*
		 * Perform search
		 */
		if (!$resource->getSkillMatrix($ageYear,$ageMonth)) {
			/*
			 * We're not doing a skills matrix because the child is
			 * too old.  Do something else instead.
			 */
		}
	}
}  else {
	$errorDivDisplay = 'none';
}

if ($_GET['step'] == 2) {
	$notCheckedArray = $resource->getResourceProviders();
}

?>
	<div id="subPage">
		<div class="leftCol">
		
			<div id="subPageContent" class="flex">
				<h1><?=$translate->_('Find local resources'); ?></h1>
				
				<div id="errorMessage" class="errorMessageBig" style="display: <?=$errorDivDisplay; ?>;"><?=$errorMessage; ?></div>
				<? if ( (($error == 1) || ($_GET['search'] != 1)) && ($_GET['step'] != 2) ) { ?>
					<form action="resourceSearch.php?search=1" method="POST">
						<label class="bigLabel" for="zip"><? echo $translate->_('Zip Code'); ?></label>
						<input class="inline" type="text" style="width: 125px;" id="zip" name="zip" value="<?=$zip; ?>" />
						<br style="clear: left;">
						
						<label class="bigLabel" for="age"><? echo $translate->_('Age of Child'); ?></label>
						<select id="ageYear" name="ageYear" style="width: 60px;">
						<option><? echo $translate->_('Years'); ?></option>
						<?
						for($a=0;$a<=21;$a++) {
							echo '<option value="'.$a.'"';
							if (!empty($ageYear) && ($ageYear == $a) ) {
								echo ' selected ';
							}
							echo '>'.$a.'</option>';
						}
						?>
						</select>
						<select id="ageMonth" name="ageMonth" style="width: 68px;">
						<option><? echo $translate->_('Months'); ?></option>
						<?
						for($a=1;$a<=12;$a++) {
							echo '<option value="'.$a.'"';
						if (!empty($ageMonth) && ($ageMonth == $a) ) {
								echo ' selected ';
							}
							echo '>'.$a.'</option>';
						}
						?>
						</select>
						<br style="clear: left;">
						
						<label></label>
						<input type="submit" value="<? echo $translate->_('Search'); ?>" class="buttonSearch" title="<? echo $translate->_('Search'); ?>" />
						<br style="clear: left;">
					</form>
					<p style="height: 100px;"></p>			
				<? } elseif ($_GET['step'] == 2) { ?>
					<p style="margin-top: 10px;">
					<div class="hiLite" style="padding-top: 5px;">
						<h2 style="float: left; width: 75%; margin: 5px;">Search Results</h2>
					
						<div style="float: left; width: 10%;">
							<p><div class="buttonSearchLink"><a href="resourceSearch.php" title="<?=$translate->_('Search again'); ?>" style="padding-top: 10px;"><?=$translate->_('Search'); ?></a></div></p>
						</div>
						<div style="clear: left;"></div>
					</div>
					
					<?
					echo $resource->renderResourceSearchHTML();
					?>
					
					</p>
				<? } else { ?>
												
				<p style="margin-top: 10px;">
					<form action="<?=$_SERVER['PHP_SELF']; ?>?step=2" method="POST">
					<input type="hidden" name="zip" value="<?=$zip; ?>" />
					<?
					echo $resource->renderResourceSearchHTML();					
					?>
					<input type="submit" style="margin-top: 10px; float: right;" value="<? echo $translate->_('Next'); ?>" class="buttonNext" title="<? echo $translate->_('Next'); ?>" />
					</form>
				</p>				
				<? } ?>				
			</div>
		</div>
		<div class="rightCol noPrint">
			<div class="rightColInner flex" style="height: 500px;">
				<? include('includes/rightColumn.php'); ?>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>	
	
	
<?
include('includes/footer.php');
?>